/**
 * Created by Administrator on 2016-07-20,0020.
 */

var Product = require('../models/product');
var mongoose = require('mongoose');
mongoose.connect('localhost:27017/shopping');

var products = [
    new Product({
        imagePath:'1.jpg',
        title:"奥迪",
        description:"奥迪",
        price:120
    }),
    new Product({
        imagePath:'2.jpg',
        title:"法拉利",
        description:"法拉利",
        price:130
    }),
    new Product({
        imagePath:'3.jpg',
        title:"兰博基尼",
        description:"兰博基尼",
        price:140
    }),
    new Product({
        imagePath:'4.jpg',
        title:"跑车",
        description:"跑车",
        price:150
    }),
    new Product({
        imagePath:'5.jpg',
        title:"宝马",
        description:"宝马",
        price:160
    }),
    new Product({
        imagePath:'6.jpg',
        title:"沃尔沃",
        description:"沃尔沃",
        price:170
    })
]

var done = 0;

for(var i = 0; i < products.length; i++) {
    products[i].save(function (err, result) {
        done++;
        if (done === products.length) {
            exit();
        }
    });
}

function exit() {
    mongoose.disconnect();
}